<!--
* description: 技术支持管理-案例管理
* author: wangjuan
* createdDate: 2021-3-8
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-more-btn="true"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :refresh-table-key="refreshTableKey"
    />

    <audit
      :key="auditPopupsKey"
      :dynamic-edit-row-data="auditRowData"
      :popups-visible.sync="auditPopupsVisible"
      :popups-state="editPopupsState"
    />

    <detail
      :key="detailPopupsKey"
      :dynamic-edit-row-data="detailRowData"
      :popups-visible.sync="detailPopupsVisible"
      :popups-state="editPopupsState"
    />

    <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible.sync="editPopupsVisible"
      :popups-state="editPopupsState"
    />
  </div>
</template>
<script>

import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import Vue from 'vue'
import { orgApis } from '@/api/caseManagementQuery'
export default {
  name: 'StoreReturnRegistration',

  components: {
    OneTableTemplate,
    Edit: () => import('./edit'),
    Detail: () => import('./detail'),
    Audit: () => import('./audit')
  },

  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      editRowData: {},
      editPopupsVisible: false,

      detailPopupsKey: '1',
      detailRowData: {},
      detailPopupsVisible: false,

      auditPopupsKey: '11',
      auditRowData: {},
      auditPopupsVisible: false,
      // 网格查询API配置对象
      apiConfig: orgApis.queryTechnicalSupport,

      refreshTableKey: '0',

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'),
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey2',
          size: 'small',
          name: 'add',
          clickEvent: this.add,
          text: this.$t('sys.button.add'),
          position: 'left'
        },
        {
          compKey: 'btnKey3',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right'
        }
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'compKey1',
              labelName: '案例编码：',
              codeField: 'reportCode',
              lookuptype: 'VE0212',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '门店编码：',
              codeField: 'dlrCode',
              lookuptype: 'VE0207',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '门店名称：',
              codeField: 'dlrFullName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey4',
              labelName: '提报日期：',
              codeField: 'submitStartDate,submitEndDate',
              component: () => import('@/components/org/datePicker/datePicker'),
              dateType: 'daterange',
              isMust: true
            },
            {
              compKey: 'compKey5',
              labelName: '主题：',
              codeField: 'topic',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false
            },
            {
              compKey: 'compKey6',
              labelName: '审核人：',
              codeField: 'checkEmpid',
              component: () => import('@/components/org/commonInput'),
              type: 'dropdownList',
              isMust: false
            },
            {
              compKey: 'compKey7',
              labelName: '审核日期：',
              codeField: 'checkStartDate,checkEndDate',
              component: () => import('@/components/org/datePicker/datePicker'),
              dateType: 'daterange',
              isMust: false
            },
            {
              compKey: 'compKey8',
              labelName: '状态：',
              codeField: 'statusCode',
              component: () => import('@/components/org/LookupValue'),
              oFields: 'statusCode,returnStatusName',
              options: [
                { statusCode: '1', returnStatusName: '保存' },
                { statusCode: '2', returnStatusName: '提交' },
                { statusCode: '3', returnStatusName: '驳回' },
                { statusCode: '4', returnStatusName: '审核通过' }
              ],
              type: 'dropdownList',
              isMust: false
            }
          ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'releaseId',
              label: '主键ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发控制ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'controlBtn1',
              label: '操作',
              width: 150,
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey1',
                  labelName: '审核',
                  rowFileds: 'show:status--审核通过',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: (index) => this.audit(index)
                },
                {
                  compKey: 'propKey2',
                  labelName: '详情',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: (index) => { this.detail(index) }
                }
              ]
            },
            {
              prop: 'reportCode',
              label: '案例编码'
            },
            {
              prop: 'dlrCode',
              label: '门店编码'
            },
            {
              prop: 'dlrFullName',
              label: '门店名称'
            },
            {
              prop: 'submitDate',
              label: '提报日期',
              width: 140
            },
            {
              prop: 'topic',
              label: '主题'
            },
            {
              prop: 'submitEmpid',
              label: '填报人'
            },
            {
              prop: 'status',
              label: '状态'
            }
          ],

      // 表单查询数据
      formField: this.$utils.getFormField(this, {
        reportCode: '',
        dlrCode: '',
        dlrFullName: '',
        submitStartDate: '',
        submitEndDate: '',
        topic: '',
        checkEmpid: '',
        checkStartDate: '',
        checkEndDate: '',
        statusCode: ''
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },

  mounted() {
    // 列表查询
    this.queryTable(1)
  },

  methods: {
    // 编辑
    edit(index) {
      this.editPopupsState = 'edit'
      this.editPopupsVisible = true
      this.editRowData = this.$refs['multipleTable'].list[index]
    },

    audit(index) {
      this.editPopupsState = 'edit'
      this.auditPopupsVisible = true
      this.auditRowData = this.$refs['multipleTable'].list[index]
    },

    add() {
      this.editPopupsState = 'add'
      this.editPopupsVisible = true
    },

    detail(index) {
      this.editPopupsState = 'edit'
      this.detailPopupsVisible = true
      this.detailRowData = this.$refs['multipleTable'].list[index]
    }
  }
}
</script>
